package com.cxy.datawarehouse.controller;


import com.cxy.datawarehouse.biz.StandardCodeBiz;
import com.cxy.datawarehouse.entity.StandardCode;
import com.cxy.datawarehouse.entity.StandardCodeDetail;
import com.cxy.datawarehouse.response.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags="标准代码")
@RestController
@Validated
@Slf4j
@RequestMapping("/standardCode")
public class StandardCodeController {
    @Resource
    StandardCodeBiz standardCodeBiz;

    @GetMapping(value = "/list")
    @ApiOperation("标准代码列表")
    public Result<List<StandardCode>> list(){
        List<StandardCode> list = standardCodeBiz.list();
        return Result.ok(list);
    }

    @GetMapping(value = "/getByTypeId/{id}")
    @ApiOperation("通过类别获取标准代码")
    public Result<List<StandardCode>> getByTypeId(@PathVariable Long id){
        return Result.ok(standardCodeBiz.getByTypeId(id));
    }

    @GetMapping(value = "/getById/{id}")
    @ApiOperation("通过Id获取标准代码")
    public Result<StandardCode> getById(@PathVariable Long id){
        return Result.ok(standardCodeBiz.getById(id));
    }

    @PostMapping(value = "/update")
    @ApiOperation("修改标准代码信息")
    public Result<Long> getById(@RequestBody StandardCode standardCode){
        standardCodeBiz.update(standardCode);
        return Result.ok();
    }

    @PostMapping(value = "/create")
    @ApiOperation("创建标准代码")
    public Result<Long> create(@RequestBody StandardCode standardCode){
        standardCodeBiz.create(standardCode);
        return Result.ok();
    }

    @PostMapping(value = "/deleteById/{id}")
    @ApiOperation("通过Id删除标准代码")
    public Result<Long> deleteById(@PathVariable Long id){
        standardCodeBiz.deleteById(id);
        return Result.ok();
    }

    @PostMapping(value = "/stopById/{id}")
    @ApiOperation("停用标准代码")
    public Result<Long> stopById(@PathVariable Long id){
        standardCodeBiz.stopById(id);
        return Result.ok();
    }

    @PostMapping(value = "/openById/{id}")
    @ApiOperation("停用标准代码")
    public Result<Long> openById(@PathVariable Long id){
        standardCodeBiz.openById(id);
        return Result.ok();
    }
}
